#pragma once
#include "Window.h"
#include "LayerStack.h"

#include "SourceCode/ImGui/ImGuiLayer.h"
#include "SourceCode/Events/ApplicationEvent.h"

namespace Hazal
{
	class HZ_DLL_OPTION CApplication
	{
	public:
		CApplication();

		virtual ~CApplication();

	public:
		void Run();

		/// <summary>
		/// 窗口事件回调函数, 表示由App对象捕捉事件
		/// </summary>
		/// <param name="e"></param>
		void OnEvent(CEvent& e);

		/// <summary>
		/// 将Layer压入LayerStack
		/// </summary>
		/// <param name="layer"></param>
		void PushLayer(CLayer* layer);

		/// <summary>
		/// 将Layer压入LayerStack最上层
		/// </summary>
		/// <param name="layer"></param>
		void PushOverlay(CLayer* overlay);

		/// <summary>
		/// 获取单例
		/// </summary>
		/// <returns></returns>
		inline static CApplication& Instance() { return *s_Instance; }

		/// <summary>
		/// 获取应用程序绑定的window
		/// </summary>
		/// <returns></returns>
		inline CWindow& GetWindow() const { return *m_Window; }


		/// <summary>
		/// 关闭窗口
		/// </summary>
		inline void Close() { m_bRunning = false; }

		inline CImGuiLayer* GetImGuiLayer() { return m_ImGuiLayer; }

	private:
		/// <summary>
		/// 窗口关闭事件的响应
		/// </summary>
		/// <param name="e"></param>
		/// <returns></returns>
		bool OnWindowClose(CWindowCloseEvent& e);

		/// <summary>
		/// 窗口大小变更事件的响应
		/// </summary>
		/// <param name="e"></param>
		/// <returns></returns>
		bool OnWindowResize(CWindowResizeEvent& e);

	private:
		Scope<CWindow> m_Window;			///< 应用开启的主窗口
		CImGuiLayer* m_ImGuiLayer;			///< 应用开启后自带的ImGui层, 由应用管理

		bool m_bRunning;
		bool m_bMinimized;					///< 窗口最小化状态

		CLayerStack m_layerStack;			///< 渲染层栈

	private:
		static CApplication* s_Instance;	///< 单例
	};

	CApplication* CreateApplication();
}

